<?php

namespace app\admin\model;

use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;

class ImageZoneModel extends Model
{
    //分页查询
    public function list($page, $limit)
    {
        return Db::table('image_zone')->order('add_time', 'desc')->page($page, $limit)->select();
    }

    public function selectByMd5($md5)
    {
        try {
            return Db::table('image_zone')->where('md5', $md5)->find();
        } catch (Exception $e) {
            return -1;
        }
    }

    public function add($data)
    {
        Db::table('image_zone')->insert($data);
    }

    public function update($id, $data)
    {
        Db::table('image_zone')->where('id', $id)->update($data);
    }

    public function count(): int
    {
        $list = Db::table('image_zone')->select();
        return count($list);
    }

    public function delete($md5): int
    {
        try {
            return Db::table('image_zone')->where('md5', $md5)->delete();
        } catch (Exception $e) {
            return -1;
        }
    }


}